const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const { VueLoaderPlugin } = require('vue-loader')
module.exports = {
  mode: 'development',
  entry: {
    main: './src/main.js',
    manage: './src_manage/main.js',
  },
  output: {
    filename: 'js/[name].js',
    path: path.resolve(__dirname, './dist'),
  },
  module: {
    rules: [
      { test: /\.vue$/, loader: 'vue-loader' },
      { test: /\.css$/, use: ['style-loader', 'css-loader'] },
      {
        test: /\.(png|ico)$/,
        type: 'asset/resource',
        generator: {
          filename: 'images/[hash:8][ext6]',
        },
      },
      {
        test: /\.m?js$/,
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: ['@babel/preset-env'],
          },
        },
      },
    ],
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: './public/index.html',
      filename: 'index.html',
      // 配置模板文件中需要包含哪些js文件，
      // 如果不配置则默认全部引入
      chunks: ['main'],
    }),
    new HtmlWebpackPlugin({
      template: './public/index_manage.html',
      filename: 'index_manage.html',
      chunks: ['manage'],
    }),
    new VueLoaderPlugin(),
  ],
}
